package com.renwei.yunlong.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.renwei.yunlong.R;
import com.renwei.yunlong.bean.MuchAssetBean;
import com.zyf.fwms.commonlibrary.base.baseadapter.BaseRecyclerViewAdapter;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by wangqi on 2017/11/23.
 * 多对象
 */

public class WorkDetailObjectAdapter extends BaseRecyclerViewAdapter<MuchAssetBean> {

    public void setShow(boolean show) {
        isShow = show;
    }

    private boolean isShow;
    private boolean isWork;

    public WorkDetailObjectAdapter(Context context,boolean isWork) {
        super(context);
        this.isWork = isWork;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new MyHolder(inflater.inflate(R.layout.item_work_detail_object, parent, false));
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, final int position) {
        MyHolder myHolder = (MyHolder) holder;
        MuchAssetBean bean = getItem(position);

        if (isShow){
            myHolder.rlProgress.setVisibility(View.VISIBLE);
        }else{
            myHolder.rlProgress.setVisibility(View.GONE);
        }
        myHolder.tvService.setText(bean.getDirectoryName());
        myHolder.tvObject.setText(bean.getAssetName());
        myHolder.tvProgress.setText(bean.getSolutionState());
        if (TextUtils.isEmpty(bean.getAssetId())){
            myHolder.ivObject.setVisibility(View.GONE);
        }else{
            if (isWork){
                myHolder.ivObject.setVisibility(View.VISIBLE);
            }else{
                myHolder.ivObject.setVisibility(View.GONE);
            }
        }

        myHolder.ivObject.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                //对象选择
                mOnItemClickLitener.onItemClick(view, position);
            }
        });

    }

    class MyHolder extends RecyclerView.ViewHolder {
        @Bind(R.id.tv_object)
        TextView tvObject;
        @Bind(R.id.rl_iv_object)
        RelativeLayout ivObject;
        @Bind(R.id.tv_service)
        TextView tvService;
        @Bind(R.id.tv_progress)
        TextView tvProgress;
        @Bind(R.id.rl_progress)
        RelativeLayout rlProgress;

        public MyHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
